# plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=1)
import cv2
import numpy as np
from charset_normalizer.utils import is_ascii

from yolo.utils.plots import plot_one_box


class AnnotatorP:
    # YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
    def __init__(self, im, line_thickness=None, font_size=None, font='simfang.ttf', pil=False, example='xyz'):
        assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to Annotator() input images.'
        self.im = im
        self.lw = line_thickness or max(round(sum(im.shape) / 2 * 0.003), 2)  # line width

    def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
        # Add one xyxy box to image with label
        plot_one_box(box, self.im, label=label, color=color, line_thickness=self.lw)

    def result(self):
        # Return annotated image as array
        return np.asarray(self.im)